<template>
  <div>
    <el-form :model="queryParam" :inline=true style="display: flex">
      <el-form-item label="字段">
        <el-input v-model="queryParam.code" style="width:160px"/>
      </el-form-item>
      <el-form-item label="名称">
        <el-input v-model="queryParam.name" style="width:160px"/>
      </el-form-item>
      <el-form-item label="数据类型">
        <el-input v-model="queryParam.dataType" style="width:100px"/>
      </el-form-item>
      <el-form-item label="默认值">
        <el-input v-model="queryParam.defaultValue" style="width:60px"/>
      </el-form-item>
      <el-form-item label="有效否">
        <el-select v-model="queryParam.isValid" placeholder="请选择" :clearable=true style="width:100px">
          <el-option v-for="t in validEnums" :label="t.name" :value="t.value" :key="t.value"/>
        </el-select>
      </el-form-item>
      <el-form-item label="groovy脚本">
        <el-input v-model="queryParam.groovy" style="width:160px"/>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="queryPage">搜索</el-button>
      </el-form-item>
    </el-form>

    <el-table :data="tableData" stripe style="width: 100%">
      <el-table-column prop="id" label="序号" width="80"></el-table-column>
      <el-table-column prop="code" label="字段" width="100"></el-table-column>
      <el-table-column prop="name" label="名称" width="120"></el-table-column>
      <el-table-column prop="dataType" label="数据类型" width="80"></el-table-column>
      <el-table-column prop="defaultValue" label="默认值" width="80"></el-table-column>
      <el-table-column prop="isValid" label="有效否" width="80">
        <template slot-scope="scope">
          <span>{{ value2Name(validEnums, scope.row.isValid) }}</span>
        </template>
      </el-table-column>
      <el-table-column prop="createTime" label="创建时间" width="160">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createTime) }}</span>
        </template>
      </el-table-column>
      <el-table-column prop="groovy" label="groovy脚本">
        <template slot-scope="scope">
          <div class="typeEnter">{{ scope.row.groovy  | ellipsis }}</div>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="pageTotal>0"
      :total="pageTotal"
      :page.sync="queryParam.pageNum"
      :limit.sync="queryParam.pageSize"
      @pagination="queryPage"
    />
  </div>
</template>

<script>
import {value2Name, ellipsis, parseTime} from '@/utils'
import store from "../../../store";

export default {
  data() {
    return {
      // 查询参数
      pageTotal: 0,
      queryParam: {
        code: '',
        name: '',
        dataType: '',
        defaultValue: '',
        groovy: '',
        pageNum: 1,
        pageSize: 10
      },
      validEnums: store.listDictionary('isValid'),
      tableData: []
    }
  },
  mounted() {
    this.pageList()
  },
  methods: {
    parseTime,
    value2Name,
    queryPage() {
      let _this = this
      _this.pageList()
    },
    pageList() {
      let _this = this
      this.$api.variablePageList(_this.queryParam).then(res => {
        if (res.code === '00000') {
          _this.tableData = res.data.pageList
          _this.pageTotal = res.data.pageTotal
        } else {
          _this.$message(res.msg)
        }
      }).catch(e => {
        console.log('接口访问异常!')
      })
    }
  },
  filters: {
    ellipsis: (str) => ellipsis(str, 300)
  }
}
</script>
